package com.eastone.user.serverapi.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eastone.user.serverapi.dao.InfoUserDao;
import com.eastone.user.serverapi.model.InfoUser;
import com.eastone.user.serverapi.service.InfoUserService;
import com.yjx.framework.cache.ServiceResultCodeCache;

import com.yjx.framework.model.ServiceResult;

@Service("infoUserService")
public class InfoUserServiceImpl implements InfoUserService {
	@Autowired
	private InfoUserDao infoUserDao;
	private static ServiceResultCodeCache resultCode = ServiceResultCodeCache.getInstance();

	@Override
	public InfoUser get(int id) {
		return infoUserDao.get(id);
	}

	@Override
	public ServiceResult<String> add(InfoUser infoUser) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoUserDao.add(infoUser);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> addSelective(InfoUser infoUser) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoUserDao.addSelective(infoUser);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> update(InfoUser infoUser) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoUserDao.update(infoUser);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> updateSelective(InfoUser infoUser) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoUserDao.updateSelective(infoUser);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public ServiceResult<String> delete(InfoUser infoUser) {
		ServiceResult<String> serviceResult = new ServiceResult<String>();
		int result = infoUserDao.delete(infoUser);
		if (result == 1) {
			serviceResult.setCode(resultCode.get("common.sucess"));
		} else {
			serviceResult.setCode(resultCode.get("common.fail"));
		}
		return serviceResult;
	}

	@Override
	public List<InfoUser> getList(String userName, String userId, String phoneNum, String email, String sex, int pageNo,
			int pageSize) {
		return infoUserDao.getList(userName, userId, phoneNum, email, sex, pageNo, pageSize);
	}

	@Override
	public int getCount(String userName, String userId, String phoneNum, String email, String sex) {
		return infoUserDao.getCount(userName, userId, phoneNum, email, sex);
	}
}
